package com.example.weexnews;

import com.alibaba.fastjson.JSON;
import com.taobao.weex.bridge.JSCallback;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class NetUtil {

    private static OkHttpClient sClient = new OkHttpClient();

    public static void getNet(final String url, final JSCallback callback) throws IOException {
        Executors.newFixedThreadPool(3).execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Request request = new Request.Builder()
                            .url(url)
                            .build();
                    Response response = sClient.newCall(request).execute();
                    String responseString = response.body().string();
                    Map<String, Object> resp = new HashMap<>();
                    resp.put("data", JSON.parse(responseString));
                    callback.invoke(resp);
                } catch (Exception e) {
                }
            }
        });
    }
}
